技术标签: c++ css python java 编程语言
c语言条件语句示例
C/C++ programming languages provides switch ... case
statement for selection according to given switch state. switch ... case
can be used for different cases in order to control the flow of the application.
C / C ++编程语言提供了switch ... case
语句,用于根据给定的switch状态进行选择。 switch ... case
可以用于不同的情况,以控制应用程序的流程。
switch ... case
has the following syntax.
switch ... case
具有以下语法。
switch(EXPRESSION)
{
case CONDITION1:
CASE1_CODE;
break;
case CONDITION2:
CASE1_CODE;
break;
...
default:
DEFAULT_CODE;
}
Well, the switch case statement is a bit hard to understand according to the other keywords and mechanisms because it contains a lot of code.
好吧,根据其他关键字和机制,switch case语句有点难以理解,因为它包含很多代码。
#include <stdio.h>
int main () {
/* Variable which will be used inside the switch case */
char mygrade = 'B';
switch(mygrade) {
case 'A' :
printf("Your grade is A\n" );
break;
case 'B' :
printf("Your grade is B\n" );
break;
case 'C' :
printf("Your grade is C\n" );
break;
case 'D' :
printf("Your grade is D\n" );
break;
case 'E' :
printf("Your grade is E\n" );
break;
case 'F' :
printf("Your grade is F\n" );
break;
default :
printf("Invalid grade\n" );
}
return 0;
}
In this example, we will set the variable mygrade
as B
and this will match with the case B
and print to the screen Your grade is B
.
在此示例中,我们将变量mygrade
设置为B
,这将与情况B
匹配,并显示在屏幕上mygrade
Your grade is B
While using switch ... case
statement there are some rules to obey.
在使用switch ... case
语句时,需要遵守一些规则。
default
statement is used to run code if there is no match in the existing cases. This can be very helpful to run code in unspecified cases. We will add the default
ad the end of the cases and do not provide any case and just provide the default code block we want to run. In the following example we will provide mygrade
as Z
so it will match the default case and print screen Invalid grade
.
如果在现有情况下不匹配,则使用default
语句运行代码。 这对于在未指定的情况下运行代码非常有帮助。 我们将在案例结尾处添加default
广告,不提供任何案例,而仅提供我们要运行的默认代码块。 在下面的示例中,我们将mygrade
提供为Z
因此它将与默认情况和打印屏幕Invalid grade
匹配。
#include <stdio.h>
int main () {
/* Variable which will be used inside the switch case */
char mygrade = 'Z';
switch(mygrade) {
case 'A' :
printf("Your grade is A\n" );
break;
case 'B' :
printf("Your grade is B\n" );
break;
case 'C' :
printf("Your grade is C\n" );
break;
case 'D' :
printf("Your grade is D\n" );
break;
case 'E' :
printf("Your grade is E\n" );
break;
case 'F' :
printf("Your grade is F\n" );
break;
default :
printf("Invalid grade\n" );
}
return 0;
}
The normal behavior of the switch case is flowing from top to down and run matches cases code block and continue for the following cases. But this is generally unwanted situations where after a case is matched and code block executed we generally prefer to exit from switch case. We can use break
statement after executing a case code block which will end the switch case completely and does not check for the following cases.
开关案例的正常行为是从上到下流动的,并且运行匹配案例代码块,并在以下情况下继续运行。 但这通常是不希望的情况,在匹配大小写并执行代码块之后,我们通常更喜欢退出切换大小写。 我们可以在执行案例代码块之后使用break
语句,该代码块将完全结束切换案例,并且不会检查以下案例。
翻译自: https://www.poftut.com/switch-case-statement-in-c-c-tutorial-with-examples/
c语言条件语句示例
文章浏览阅读168次。应用程序组件是一个Android应用程序的基本构建块。这些组件由应用清单文件松耦合的组织。AndroidManifest.xml描述了应用程序的每个组件,以及他们如何交互。以下是可以在Android应用程序中使用的四个主要组件。组件 描述 Activities 描述UI,并且处理用户与机器屏幕的交互。 Services 处理与应用程序关联的后台操作。 Broadcast Receivers 处理Android操作系统和应用程序之间的通信。 Content Prov_android清单文件包含了组成应用程序模块所需要的组件
文章浏览阅读387次。1.字符转换输出递归按位输出_a.c: in function ‘main’:
文章浏览阅读6.9w次,点赞137次,收藏246次。表弟大周末的跑来我家,没事干天天骚扰我,搞得我都不能跟小姐姐好好聊天了,于是为了打发表弟,我决定用Python做一个小游戏来消耗一下他的精力..._python蔡徐坤代码复制
文章浏览阅读1.9k次。blueski推荐 [2007-1-31]出处:Java夜无眠作者:蔡学镛 1、系统分析是什么? 系统分析工作是解决一个问题的工作,目标是将一个对计算机应用系统的需求转化成实际的物理实现,其中复杂就复杂在实际的面太多.在系统分析过程之中注意问以下的问题,可能会所进行的系统分析设计工作有帮助。 1)您所完成的系统目的是什么?注意不是功能要求,而是目的.也就是为什么要建设、为什么要现_信息系统开发中分析与设计的重要性。
文章浏览阅读659次。nginx软件学习nginx是个web服务器,常用作静态文件服务器,反向代理服务器,邮件代理服务器,负载均衡服务器1.安装淘宝nginx,编代码编译安装,先解决模块依赖 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel..._nginx 使用pipe:rollback
文章浏览阅读6.7k次。pycharm安装库包失败:比如安装matplotlib失败下载库文件:https://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib根据python版本等来选择适合的文件,比如python3.8选择cp38,python3.10选择cp310,这里我选择的是matplotlib‑3.4.3‑cp310‑cp310‑win_amd64.whl将下载好的文件放入python安装包的Scripts中,运行cmd命令行,执行pip install .\_one893.app
文章浏览阅读295次。回溯算法:回溯算法实际上一个类似枚举的搜索尝试过程,主要是在搜索尝试过程中寻找问题的解,当发现已不满足求解条件时,就“回溯”返回,尝试别的路径。回溯法是一种选优搜索法,按选优条件向前搜索,以达到目标。但当探索到某一步时,发现原先选择并不优或达不到目标,就退回一步重新选择,这种走不通就退回再走的技术为回溯法,而满足回溯条件的某个状态的点称为“回溯点”。许多复杂的,规模较大的问题都可以使用回..._leetcode 306、python
文章浏览阅读352次。数据库redis使用优点使用方法redis的简单类型String字符串注意一个键最大能存储512MB哈希list列表set集合注意redis安全可以通过以下命令查看是否设置了密码验证用python实现链接数据库redis-connectredis密码破解redis使用设置数据添加数据redis查看服务器配置插入值追加数据setget数据导出dumprdb 这个即为_redis.redis(host='127.0.0.1', port=6379)
文章浏览阅读1k次。华为以“比特驱动瓦特,共建全联接智能电网”为主题,举办第七届华为全球电力峰会(线上),邀请来自全球各地的客户、伙伴、行业精英和思想领袖共同探讨。面对2020年的全球疫情、政治、经济等不确..._ict数字化解决方案资金分配
文章浏览阅读733次。 1、新建一个类库,例如库名为 ResourcesLibrary;2、添加引用 System.Drawing;3、添加资源文件(添加--新建项--资源文件),例如文件名为 Resource1.resx;4、添加图片(打开Resource1.resx,单击“添加资源”后的小三角,选择添加现有文件,选择需要作为资源的图片),例如添加了图片 Sunset.jpg5、添加类,例如名为 GetImage_易语言dll加入资源
文章浏览阅读4.4k次,点赞4次,收藏15次。今天有学生问个关于MySQL时间操作的问题,直接看图: 查询某日人员的出勤时间问题。我们都知道,企业员工考勤使用打卡方式,每天会记录每个员工的多次打卡记录,最后取每个员工的每天:上班时间:当日最早时间;下班时间:当日最晚时间。所以分析查询每个员工每日考勤记录,需要根据员工分组,当天时间、时间最小和最大,时间格式化等操作,下面举例模拟该问题:学生表student ..._%h:%i
文章浏览阅读1.3w次,点赞4次,收藏31次。Python实战——1_1.网页制作引言网页的组成部分:CSS样式 - 给结构以装饰Html - 结构部分JavaScript- 功能实现代码部分第一部分为网站的基本结构(在IDE中新建网页后既给出) {% for docs in toc_list %} "