Is there any way in if...else statement so that both the if and else statement gets executed(by applying condition in if statement).
if statement problem.
Page 1 of 12 Replies - 886 Views - Last Post: 09 September 2013 - 08:46 AM
Replies To: if statement problem.
#2
Re: if statement problem.
Posted 09 September 2013 - 03:58 AM
No only one or the other will execute. If you want both to execute at the same time you don't need an if/else.
Jim
Jim
#3
Re: if statement problem.
Posted 09 September 2013 - 08:46 AM
Quote
Is there any way in if...else statement so that both the if and else statement gets executed(by applying condition in if statement).
You can not execute multiple control paths in a if-else, it's a one-hot structure. You can however do work in the conditions, and only execute the paths for error handling.
i.e.
int sockfd;
/* execute all condition work until one of them fails */
if((sockfd = socket(/* params */)) < 0) {
/* socket error here */
}
else if(bind(sockfd, /* parameters */) < 0) {
/* bind error */
}
else {
/* success */
}
This post has been edited by jjl: 09 September 2013 - 08:47 AM
Page 1 of 1

New Topic/Question
Reply


MultiQuote



|