c - 不想打印多条语句
问题描述
当打印语句“不是字母表中的字母”时,我不希望我的代码打印其他语句。请帮忙!我还是个菜鸟。
#include <stdio.h>
int main()
{
char ch;
int int_ch;
do {
printf("Type in an alphabet letter:");
scanf("%c%*c", &ch);
int_ch = (int)ch;
printf("Ch has ascii value %d\n", ch);
if ((ch >= 'a') && (ch <= 'z'))
{
int_ch = int_ch - 32;
}
else if ((ch >= 'A') && (ch <= 'Z'))
{
int_ch = int_ch + 32;
}
else
{
printf("Is not a letter of the Alphabet.");
}
//THIS HERE
ch = (char)int_ch;
printf("Ch is now %c\n", ch);
printf("Ch is now ascii value %d\n", int_ch);
} while (ch != '#');
return (0);
}
解决方案
添加continue
是这个else-statement
else
{
printf("Is not a letter of the Alphabet.");
continue;
}
该continue
语句跳过循环的当前迭代并继续下一次迭代。
推荐阅读
- python - 在 jupyter notebook 上导入 csv 数据的问题
- swift - 我们如何获得上一行和下一行的范围?
- python - 如何比较两个列表以保持匹配的子字符串以及如何保留基于子字符串的顺序?
- sql - SQL:检测具有相同键的连续行的连续块
- css - 如何应用纵横比媒体查询
- azure - Azure 数据工厂错误:“附近有不正确的语法”
- python - 如何将模型的输入张量传递给损失函数?
- firebase - 允许未经身份验证的用户写入 Firestore
- flutter - Flutter如何按条件过滤数组
- survival-analysis - 有谁知道如何使用 ggadjustedcurves 添加置信区间和风险表?