不可抗力条款

Till now we have learnt about the if statement, if-else statement, if-else nested statements and logical operators. Logical operators are good alternatives of nested if-else statements. But there are still some cases when we have to use nested if-else clause. So to make those situations a bit easy, Dennis Ritchie introduced else if clause.

What are else if clause?

Well they are no major difference between nested if-else and else if clause. As I told you earlier, the main problem with nesting is that it makes the program difficult to read. So to avoid that issue, else if clause is introduced.

General Syntax of else if clause is given below.

if (condition)
{
Statement 1
Statement 2 and so on
}

else if (condition)
{
Statement 1
Statement 2 and so on
}

else if (condition)
{
Statement 1
Statement 2 and so on
}

else
{
Statement 1
Statememt 2 and so on
}

Things to remember while using else if clause

  • You can use any number of else if clause in this ladder.
  • Usage of else in the last is completely optional. It means its up to you that you either want to include it or not in your program.
  • This does not destroy the readability of the program.
  • By using else-if clause, our program does not creep to the right due to indentation.

Remember by using else if clause, no change will occur in the execution of program. It is just the re-write of nested if-else clause. You can understand this point by watching below example.

Lets try to understand this clause with one program.

Question: Make one program to check the eligibility of student to take admission in a college. The student must fulfil at least one condition to take admission in the college.

  • Student should be male. His marks should be more than 80% in 12th and his age should be at least 18 years.
  • Student should be female. Her marks should be more than 75% in 12th and her age should be at least 17 years.
  • Student should be played at any national level game. Age and qualification doesn’t matter in this case.
#include <stdio.h>void main ()
{int per, age;char gen, game;printf("Press M for male n F for female n Y for Yes in game n N for No in game n");printf("Enter gender, age and percentage in class 12th n");scanf("%c %d %d",&gen, &age, &per);printf("Did you play in any game at national level n");scanf("%c",&game);if ((age>=18 && per>=80 && gen=='M') || (age>=17 && per>=75 && gen=='F'))prinf("You can take admission in our college.");else if (game=='Y')printf("You can take admission based on sports Kota");elseprintf("You cannot take admission in our college.");
}

Output

Explanation

  • In the beginning we gave some instructions to user that how he/she should enter the data in our program.
  • After that we printed the message and take some details from the student.
  • Now basically we have 2 conditions. At first we have to check the student if he/she eligible for general kota and in the last we have to check if he/she is eligible for sports kota.
  • To make things a bit clear I checked the results for general kota by using if keyword. I combined the conditions by using logical operators to make the program a bit compact.
  • After that by using else if clause I have checked if the student is eligible for sports kota.
  • If nothing works then I have also given the default else block to print the message “You cannot take admission in our college.”
Till now we have learnt about the if statement, if-else statement, if-else nested statements and logical operators. Logical operators are good alternatives of nested if-else statements. But there are still some cases when we have to use nested if-else clause. So to make those situations a bit easy, Dennis Ritchie introduced else if clause.

What are else if clause?

Well they are no major difference between nested if-else and else if clause. As I told you earlier, the main problem with nesting is that it makes the program difficult to read. So to avoid that issue, else if clause is introduced.

General Syntax of else if clause is given below.

if (condition)
{
Statement 1
Statement 2 and so on
}

else if (condition)
{
Statement 1
Statement 2 and so on
}

else if (condition)
{
Statement 1
Statement 2 and so on
}

else
{
Statement 1
Statememt 2 and so on
}

Things to remember while using else if clause

  • You can use any number of else if clause in this ladder.
  • Usage of else in the last is completely optional. It means its up to you that you either want to include it or not in your program.
  • This does not destroy the readability of the program.
  • By using else-if clause, our program does not creep to the right due to indentation.

Remember by using else if clause, no change will occur in the execution of program. It is just the re-write of nested if-else clause. You can understand this point by watching below example.

Lets try to understand this clause with one program.

Question: Make one program to check the eligibility of student to take admission in a college. The student must fulfil at least one condition to take admission in the college.

  • Student should be male. His marks should be more than 80% in 12th and his age should be at least 18 years.
  • Student should be female. Her marks should be more than 75% in 12th and her age should be at least 17 years.
  • Student should be played at any national level game. Age and qualification doesn’t matter in this case.
#include <stdio.h>void main (){int per, age;char gen, game;printf("Press M for male n F for female n Y for Yes in game n N for No in game n");printf("Enter gender, age and percentage in class 12th n");scanf("%c %d %d",&gen, &age, &per);printf("Did you play in any game at national level n");scanf("%c",&game);if ((age>=18 && per>=80 && gen=='M') || (age>=17 && per>=75 && gen=='F'))prinf("You can take admission in our college.");else if (game=='Y')printf("You can take admission based on sports Kota");elseprintf("You cannot take admission in our college.");}

Output

Explanation

  • In the beginning we gave some instructions to user that how he/she should enter the data in our program.
  • After that we printed the message and take some details from the student.
  • Now basically we have 2 conditions. At first we have to check the student if he/she eligible for general kota and in the last we have to check if he/she is eligible for sports kota.
  • To make things a bit clear I checked the results for general kota by using if keyword. I combined the conditions by using logical operators to make the program a bit compact.
  • After that by using else if clause I have checked if the student is eligible for sports kota.
  • If nothing works then I have also given the default else block to print the message “You cannot take admission in our college.”

翻译自: https://www.thecrazyprogrammer.com/2015/01/c-else-if-clause.html

不可抗力条款

不可抗力条款_否则,如果条款相关推荐

  1. 合同中的不可抗力、延期和仲裁条款

    今天我们讲商务合同中的不可抗力条款.延期交货和惩罚条款和仲裁条款: Force Majeure 不可抗力条款 不可抗力条款 = 不可抗力时间 + (当事方)采取的行动 在运输中,或许会遇到一些非人为因 ...

  2. Effective C++ 小笔记:条款13-17(第三章)

    常用的资源有:内存.文件描述器(file descriptor).互斥锁(mutex locks).图形界面中的字体和笔刷.数据库连接.以及网络sockets.这些资源一般动态创建和分配,也就是一个指 ...

  3. 注意!FOB条款下,发货人还有这些费用要承担?

    我们都知道FOB(Free On Board)也称离岸价,即装运港船上交货.按FOB进行的交易,买方负责派船接运货物,卖方应在合同规定的装运港和规定的期限内将货物装上买方指定的船只,并及时通知买方.货 ...

  4. 侃一侃萨班斯法案之302条款

    布什总统在2002年7月30日签署成为正式法律称作<2002年萨班斯-奥克斯利法案>.简称SOX法案.SOX法案由302.404.906.409等条款,这里我主要说一下302条款. SOX ...

  5. Effective C++条款40:明智而审慎地使用多重继承(Use multiple inheritance judiciously)

    Effective C++条款40:明智而审慎地使用多重继承(Use multiple inheritance judiciously) 条款40:明智而审慎地使用多重继承 1.多重继承的两个阵营 2 ...

  6. App Store 审核条款最新版--iOS审核被拒的原因都在这里了--苹果应用商店审核条款

    官方的审核标准:https://developer.apple.com/app-store/review/guidelines/cn/#acceptable App 正在改变世界,丰富人们的生活,并为 ...

  7. App Store审核条款(2016.06.21更新)

    Before 一安全 1 不当内容 2 用户生成的内容 3 儿童分类 4 人身伤害 5 开发者信息 二性能 1 应用程序的完整性 2 Beta版测试 3 应用内容的准确性 4 硬件兼容性 5 软件要求 ...

  8. App Store审核条款更新:WWDC 2016重写版本

    WWDC2016大会之后,苹果公司发布了四个全新平台:iOS,macOS,watchOS和tvOS.并且在此之后,苹果应用商店审核条款也同时进行了更新--貌似不算进行了更新,简直就是重写!上个版本的3 ...

  9. 【翻新重写】WWDC 后苹果最新 App Store 审核条款!「内附最新开发者指南」

    WWDC 2016 大会之后,苹果公司发布了四个全新平台:iOS,macOS,watchOS 和 tvOS.并且在此之后,苹果应用商店审核条款也同时进行了更新--貌似不算进行了更新,简直就是重写!上个 ...

最新文章

  1. 勒索软件出新招,小心你的隐私和財产安全!
  2. devstack 安装trove newtone
  3. boost::reverse_graph用法的测试程序
  4. android graphics pipeline
  5. CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)
  6. 拓端tecdat|matlab估计arma garch 条件均值和方差模型
  7. LeetCode算法,多多路上从左到右有N棵树(编号1~N),其中第i个颗树有和谐值Ai。 多多鸡认为,如果一段连续的树,它们的和谐值之和可以被M整除,那么这个区间整体看起来就是和谐的....
  8. 番外4. Python OpenCV 中鼠标事件相关处理与常见问题解决方案
  9. KY-RTI分布仿真技术:第三章 KY-OMT对象模型模板工具
  10. QQ 邮箱设置自定义域名邮箱
  11. mysql概念模型中的3种基本联系_数据库建模三步骤:概念模型
  12. 打印时去除页眉和页脚
  13. win10系统停止更新服务器,Win10系统关闭自动更新功能的三种最佳方法
  14. 浅谈Unity中的rotation和Quaternion的乘法
  15. [语音识别] 单音素、三音素、决策树
  16. MapReduce论文阅读记录
  17. 今日头条校招真题——异或
  18. 【VMD-SSA-LSSVM】基于变分模态分解与麻雀优化Lssvm的负荷预测【多变量】(Matlab代码实现)
  19. File常用方法,不积硅步无以至千里
  20. MySQL之where查询

热门文章

  1. 电脑安全莫依赖影子系统(或冰封系统)
  2. android蓝牙和线同时播放,Android蓝牙音频播放和录制
  3. 初始C语言-1.c语言程序的组成
  4. python空间分析库_空间分析:5-1.空间分析库PySAL的使用
  5. 爬梯:Redis全解析(二)
  6. Tomcat报错:Document base ……does not exist or is not a readable directory
  7. 《乌合之众》60条基本观点
  8. 莫烦python中的DDPG运行结果
  9. 数字音频编辑器GoldWavev6.54免费版
  10. matlab-自控原理 bode 由传递函数画出bode图(幅频特性曲线)