我想跳过数字10,以便我只有数字 从15到5而没有输出数字10。
<?php
$x = 15;
while($x >=5) {
echo "$x <br>";
$x--;
}
?>
答案 0 :(得分:4)
当foreach (var individual in xelement.XPathSelectElements("LoanApp/LoanAppRq/Applicant/Personal/Individuals/Individual"))
{
// Get the first and last name.
var BORROWERFIRSTNAME = (string)individual.XPathSelectElement("GivenName/FirstName");
var BORROWERLASTNAME = (string)individual.XPathSelectElement("GivenName/LastName");
// Get the XElement for the current address.
var currentAddress = individual.XPathSelectElements("ContactInfo/Address[@Type='Current']")
.FirstOrDefault();
// Extract its properties, checking for a missing current address if necessary.
var currentZip = (currentAddress == null ? null : (string)currentAddress.Element("Zip"));
// Get the XElement for the previous address.
var previousAddress = individual.XPathSelectElements("ContactInfo/Address[@Type='Previous']")
.FirstOrDefault();
// Extract its properties, checking for a missing previous address if necessary.
var previousZip = (previousAddress == null ? null : (string)previousAddress.Element("Zip"));
// Process the borrower names and addresses as required.
}
条件等于10时,添加foreach (var individual in xelement.Elements("LoanApp")
.Elements("LoanAppRq")
.Elements("Applicant")
.Elements("Personal")
.Elements("Individuals")
.Elements("Individual"))
{
// Get the first and last name.
var BORROWERFIRSTNAME = (string)individual.Elements("GivenName")
.Elements("FirstName")
.FirstOrDefault();
var BORROWERLASTNAME = (string)individual.Elements("GivenName")
.Elements("LastName")
.FirstOrDefault();
// Get the XElement for the current address.
var currentAddress = individual.Elements("ContactInfo").Elements("Address").Where(e => (string)e.Attribute("Type") == "Current").FirstOrDefault();
// Extract its properties, checking for a missing current address if necessary.
var currentZip = (currentAddress == null ? null : (string)currentAddress.Element("Zip"));
// Get the XElement for the previous address.
var previousAddress = individual.Elements("ContactInfo").Elements("Address").Where(e => (string)e.Attribute("Type") == "Previous").FirstOrDefault();
// Extract its properties, checking for a missing previous address if necessary.
var previousZip = (previousAddress == null ? null : (string)previousAddress.Element("Zip"));
// Process the borrower names and addresses as required.
}
条件忽略if
:
$x
答案 1 :(得分:4)
<?php
for($i=15;$i>=5;$i--){
if($i == 10) continue;
echo $i . '<br>';
}
?>
或
<?php
for($i=15;$i>=5;$i--){
if($i != 10) echo $i . '<br>';
}
?>
答案 2 :(得分:1)
所有其他帖子都是正确的,但由于您正在学习,您应该在不使用速记的情况下学习,因为它有时难以阅读。
并非所有人都使用速记,并且在大多数实践中使用编码标准。我们特别不使用速记。
示例:
<?php
$x = 15;
while($x >=5 ) {
if($x != 10){
echo $x . "<br />";
}
$x--;
}
?>
答案 3 :(得分:0)
$num = 15;
while($num >=5 ) {
if($num != 10) echo $num . "\n";
$num--;
}
答案 4 :(得分:0)
没有测试的另一种方式:
$a = array_merge(range(15,11), range(9,5));
foreach($a as $num)
echo $num . '<br>';