How many times will the for loop execute?
Set String s="Pseudo"
Set Integer len=StringLength(s)
for m=0 to len step 1 do
if s[m] equals 'u' do
display "Found"
break
end-if
end-for
[2 marks]
Answers
Answered by
0
Answer:
the answer for this question is I think 10 times the loop will begin.
Answered by
0
Answer:
The for loop will execute four times.
Explanation:
The given pseudo-code is:
Set String s="Pseudo"
Set Integer len=StringLength(s)
for m=0 to len step 1 do
if s[m] equals 'u' do
display "Found"
break
end-if
end-for
- The first line of the code initializes a string variable and the second line finds the length of the string.
- Now the for loop starts running from 0 to the length of the string.
- Focus on the if statement that is written inside the for loop.
- As soon as 'u' is encountered on any index of the given string, the loop will stop running because a break statement is given after that.
- The given string is Pseudo so 'u' is encountered at the 4th index.
- So the for loop will run only for 4 tiems.
#SPJ2
Similar questions