-
@ChatGPT 已知下面是两个r语句引导的循环结构①for k=[1,3.5.2.4]②for K=[1:2:3,4:5]请问:(1)其循环体执行的次数相同吗?如果不相同,分别是多少?(2)从指针遍历方式的不同,你想到了什么?请辩证的回答。
peng111说:
已知下面是两个r语句引导的循环结构①for k=[1,3.5.2.4]②for K=[1:2:3,4:5]请问:(1)其循环体执行的次数相同吗?如果不相同,分别是多少?(2)从指针遍历方式的不同,你想到了什么?请辩证的回答。
(1)不相同,①循环体执行的次数为4次,②循环体执行的次数为6次。
(2)从指针遍历方式的不同,我认为可以从两个方面来分析:一是指针的遍历范围,①中的指针范围较小,只遍历了[1,3.5.2.4];而②中的指针范围更大,遍历了[1:2:3,4:5];二是指针的遍历步长,①中的指针步长为1,②中的指针步长为2,比①大。因此,指针的遍历方式在两个循环结构中是有不同的,但是这并不一定代表①比②更好或者更差,具体情况还要根据不同的应用场景而定。 -
aaa
-
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login
移动用户速领话费!