programming using only "if statement" (without the else part)

i want to write a program to add the digits of a 5 digit number, using only the "if statement" without the "else" part. Is is possible?
Last edited on
You can split up if-else into two ifs by making the second if condition a negation of the first.

1
2
3
4
5
6
7
8
if (condition)
{
	DoSomething();
}
else
{
	DoSomethingElse();
}

-->

1
2
3
4
5
6
7
8
if (condition)
{
	DoSomething();
}
if (!condition)
{
	DoSomethingElse();
}
I'm not even sure you'd need 'if' at all for the program he's describing.

Summing digits doesn't really require any conditional logic.
thats true -- you dont need conditional logic for that. but the project is to solve using only if statements.
Last edited on
Topic archived. No new replies allowed.