博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【错误】 “=” 与 "==" 不分
阅读量:7090 次
发布时间:2019-06-28

本文共 962 字,大约阅读时间需要 3 分钟。

#include 
using std::cin;using std::cout;using std::endl;int main() { int a,b; a =1; while (a <= 10){ cout << "第" << a << "次" << " "; if (a=10){ cout << endl; } a++; } return 0;}

上面是今天学习while是所写的代码,目的是输出while循环的次数,并在最后一次输出后换行

但编译运行的结果出乎我的意料,只输出了第一次

但在加入if语句之前并不会这样

看了几遍代码,觉得没有问题(真的)。。。

后来去问别人,发现自己又犯了同一个错误,”=“ 和 ”==“不分

 

”=“:一般是赋值给变量

”==“:判断左边是否等于右边

       等于:整个表达式的值为true

       不等于:整个表达式的值为false

 

正确的代码如下

#include 
using std::cin;using std::cout;using std::endl;int main() { int a,b; a =1; while (a <= 10){ cout << "第" << a << "次" << " "; if (a==10){ cout << endl; } a++; } return 0;}

 

反思:1.代码还是看的和敲得太少了

      2.对自己不够自信,要自信些

                                      2018.01.27

                                        水汐音

转载于:https://www.cnblogs.com/syxy/p/8366055.html

你可能感兴趣的文章
一个C++类的注释:
查看>>
Winsock IO模型之select模型
查看>>
开发规范
查看>>
union和union all的区别
查看>>
debian attempt to kill init!
查看>>
centos7下使用yum安装mysql
查看>>
jquery获取div距离顶部的距离
查看>>
CentOS使用EPEL YUM源
查看>>
大型网站架构设计及技术总结
查看>>
phpunit assert断言分类整理
查看>>
springMVC robots.txt 处理
查看>>
python2.0_s12_day19_前端模版使用
查看>>
PHP json_decode object时报错Cannot use object of type stdClass as array
查看>>
hibernate一对一外键双向关联
查看>>
SharePoint 2013 同步FBA认证用户
查看>>
二叉树的遍历实现
查看>>
Sublimetext 3 经常使用插件
查看>>
Educational Codeforces Round 11 C. Hard Process 二分
查看>>
Android Camera 使用一例,视频聊天app
查看>>
区块链代币(Token)笔记 — — 术语
查看>>