0

Hi. I need help with this algorithm. My lecturer said theres nothing wrong with the question. I dont understand the UNTIL L part

STEP 1: START STEP 2: SET m=1 STEP 3: SET k=0. REPEAT STEP 4 TO STEP 8 UNTIL k<6 STEP 4: SET L=1. REPEAT STEP 5 and STEP 6 UNTIL L STEP 5: PRINT m STEP 6: SET m=m+1, L=L+1 STEP 7: PRINT new line STEP 8: SET k= k+1 STEP 9: END

3rd Nov 2020, 11:51 AM
mahsa
mahsa - avatar
18 ответов
+ 4
Crazy....one can simply go straightforward from step1 to step9.
3rd Nov 2020, 12:26 PM
Oma Falk
Oma Falk - avatar
+ 3
mrn. The condition for repeat loop is true from the beginning.so it will be processed exactly once. A repeatUntil loop stops if cond is true but is processed at least once.
3rd Nov 2020, 2:19 PM
Oma Falk
Oma Falk - avatar
+ 2
I have recently answered a question with similar structure and problems. https://www.sololearn.com/discuss/2572492/?ref=app Maybe you have the same lecturer? It has to be "while" instead of "until", otherwise it jumps from step 3 to end right away. Javascript and other languages can implicitly cast int to boolean (0->false, everything else->true). That would produce an infinite loop since L starts at 1 and is only increased. I think the code from your lecturer is wrong. Also it lacks basic conventions like same case for all variables
3rd Nov 2020, 12:18 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 2
Martin Taylor yes and looks like he inverted the condition only but didn't change the keyword
3rd Nov 2020, 12:44 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 2
Either the question of the teacher is wrong concerning use of repeat untll loop or he built a trap.
3rd Nov 2020, 2:00 PM
Oma Falk
Oma Falk - avatar
+ 1
mrn. You can open my code and try yourself. As a condition you have to write l==k instead of l<6 It will output 1 in second line
3rd Nov 2020, 1:40 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
To understand this nested loop manually keep track and print every variable which holds a value.
5th Nov 2020, 7:56 AM
Amit Roy
Amit Roy - avatar
0
I was curious, so i tried to find an "interpretation" that makes a bit more sense. L counts up, so i decided it shall stop at 6, just like k. mrn. you gave two languages so chose Java https://code.sololearn.com/c1LbEFBmGdya/?ref=app
3rd Nov 2020, 12:48 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
Martin Taylor no i didnt mistyped it 😅
3rd Nov 2020, 1:30 PM
mahsa
mahsa - avatar
0
Benjamin Jürgens what if i put L=k? does it make sense?
3rd Nov 2020, 1:31 PM
mahsa
mahsa - avatar
0
wdym by he built a trap? Frogged
3rd Nov 2020, 2:12 PM
mahsa
mahsa - avatar
0
okay, thank you Benjamin Jürgens !
3rd Nov 2020, 2:12 PM
mahsa
mahsa - avatar
0
Benjamin Jürgens sorry i mistyped it. what i meant was L<k not L=k
3rd Nov 2020, 2:18 PM
mahsa
mahsa - avatar
- 2
Good morning. I am a newbie here. Nice to meet you all.
4th Nov 2020, 11:09 PM
JERICHO PEL
JERICHO PEL - avatar
- 2
welcome JERICHO PEL 👍🏻
4th Nov 2020, 11:37 PM
mahsa
mahsa - avatar