+ 2

If loop without any statement

I found this modular exponentiation algorithm on the internet, and i confused. Why the if loop dont have any statement? And when i erase the if loop , the output gone wrong, can anyone tell me? Thank you This is c++ program https://www.tutorialspoint.com/cplusplus-program-to-implement-modular-exponentiation-algorithm

22nd Nov 2019, 2:14 PM
Spiral Phoenix
Spiral Phoenix - avatar
5 odpowiedzi
+ 3
The first line below the if condition belongs to the if statement. When you have a single statement to execute for if then you do not need curly braces { }. Also you can make this out through indentation after if condition.
22nd Nov 2019, 2:19 PM
Avinesh
Avinesh - avatar
+ 2
Thank you guys , i didnt realize about the single statment doesnt need a curly braces, and sorry if i said if was a loop , i still new in programming :(
22nd Nov 2019, 2:25 PM
Spiral Phoenix
Spiral Phoenix - avatar
+ 2
CodeCat_ thank you once again 😁
22nd Nov 2019, 2:48 PM
Spiral Phoenix
Spiral Phoenix - avatar