Change my for loop
I have the following piece of code. How can I alter for loop so that I can remove the while condition form my code.
int a = 1; // a gets value from user
// code goes here
j = j++;
By while condition, I assume you mean the i < 10 part of your for loop. What are you trying to accomplish by getting rid of this?
I meant can we remove the if condition below and embed this in the for loop?
Apologies for the confusion.
It seems like the above code will compile but I'm not sure if it will accomplish what you want. I've never thought about putting a complex condition there.
for(int i=a;i<10 && j != 10;i++)
If all else fails, what you had in the first place is completely valid.
Perfect. It worked.
I wanted to know how to put two conditions in a for loop.