Help please. Is there anyone who can explain to me this code? | SoloLearn: Learn to code for FREE!

+2

Help please. Is there anyone who can explain to me this code?

https://code.sololearn.com/cK0pJzEOfYRR/?ref=app

c++

11/21/2020 12:33:12 PM

Selçuk ÖZÜBEK

14 Answers

New Answer

+9

(b<4) is still true when (a<1) is false for b values of 1,2,3.

+8

BeegCat when you put "(a<=1) || (b<=4)" for *b = 4* condition will still be true and program will still enter the loop. When inside the loop "a" and "b" will be incremented to 5 which will break the loop.

+5

For the value of a being less than 1 or b being less than 4, the for loop will run. As the conditions are satisfied, the values of a and b are incremented till 4, because the for loop has the condition: b<4. // You need to get familiar with the and or nor not logic gates to understand it completely. https://www.sololearn.com/learn/CPlusPlus/1619/?ref=app Conditions for a or b>4 are not defined, so you get both a and b as 4.

+5

When I add the <=1 and <=4, it gives me 5🤔 Arsenic help!!

+4

Selçuk ÖZÜBEK when b is 3, the loop condition b<4 is satisfied, so the program enter the loop and increment b. Now b is 4 and the loop condition is no longer satisfied, so the program do not rejoin the loop and a and b are left with the value of 4.

+4

Selçuk ÖZÜBEK it's not an error, is just a warning about the fact that a; and b; are useless statements.

+3

Hey Selçuk ÖZÜBEK As you know that loop will start from 0 to 3 as b<4 i.e. four time. So, For the first loop i=0 value of a and b will be incremented i.e. a=1,b=1 For the second loop i=1 value of a and b will be incremented again i.e. a=2,b=2 For the third loop i=2 value of a and b will be incremented again i.e. a=3,b=3 For the fourth loop i=1 value of a and b will be incremented again i.e. a=4,b=4

+3

Selçuk ÖZÜBEK If you remove ++ from a and b then what is the use of that for loop and a,b statements. That's why there is a error.

+2

Thank you so much guys.

+2

Thirteen; when i remove "++" from: { a++; b++; } it gives an error. Why?

+2

Thanks Thirteen

+2

a and b implement four times since a=0 and b=0 then i is an integer then || is or and then a and b are outputted.

+1

It should be (3, 3), because b<4.

+1

a =0, b=0; it declares and assigns variable a to 0 and variable b to 0. for(int i=0; (a<1)||(b<4);i++) the for loop initializes variable I to 0,And for the loop to execute either variable a must be less than 1 or b must be less than 4. a++; b++; if the for condition is true then variable a is incremented by 1 and so is b. cout<<a<<","<<b<<endl; outputs variable a plus string "," plus variable b finally line break . return 0; returns since the main function is dellaed to return an integral value that we use return 0