c++学习-基础-break-continue-goto

这篇博客探讨了C++中的break、continue和goto语句的用法。示例代码展示了如何在while、for循环中使用这些控制结构,以及在查找特定条件时它们的作用。此外,还提供了一个检查考试分数是否包含满分的程序示例。
摘要由CSDN通过智能技术生成

001

/*
	Description: 
	三个语句:
	break语句
		1.打断while
		2.打断do while
		3.打断for
		4.打断switch
	continue语句 - 提前结束当次迭代,继续循环
	goto语句 - 禁止使用! 
*/
#include<iostream>
#include<vector>
#include<ctime>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


int main()
{
	//Error 'srand' was not declared in this scope
	vector<int> vec;//考试分数 
	int r;
	srand((unsigned)time(NULL));
	for(int i = 0;i<10000;++i)
	{
		r = rand()%101;
		vec.push_back(r);
	}
	
	cout<<"检查是否有人考试一百分?"<<endl;
	vector<int>::iterator iter = vec.begin();
	while(iter != vec.end())
	{
		if(*iter == 100)
			break;
		else
			++iter;
	}
	if(iter != vec.end())
		cout<<"有人考试一百分"<<endl;
	else
		cout<<"没有人考试一百分"<<endl;
	return 0;
}

002

#include<iostream>
#include<vector>
#include<ctime>
#include <stdio.h>
#include <stdlib.h>
using namespace std;


int main()
{
	string word;
	cout<<"enter some words:(ctrl + z to end)"<<endl;
	while(cin>>word)
	{
		if(islower(word[0]))
			continue;
		else//单词的第一个字母是大写 
		{
			cout<<"找到一个大写单词:"; 
			cout<<word;
			cout<<",其长度是:";
			cout<<word.size()<<endl; 
		}
	}

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值