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
18 Réponses
+ 4
Crazy....one can simply go straightforward from step1 to step9.
+ 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.
+ 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
+ 2
Martin Taylor yes and looks like he inverted the condition only but didn't change the keyword
+ 2
Either the question of the teacher is wrong concerning use of repeat untll loop or he built a trap.
+ 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
+ 1
To understand this nested loop manually keep track and print every variable which holds a value.
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
0
Martin Taylor no i didnt mistyped it 😅
0
Benjamin Jürgens what if i put L=k? does it make sense?
0
wdym by he built a trap? Frogged
0
okay, thank you Benjamin Jürgens !
0
Benjamin Jürgens sorry i mistyped it. what i meant was L<k not L=k
- 2
Good morning. I am a newbie here. Nice to meet you all.
- 2
welcome JERICHO PEL 👍🏻